package com.logger.Point;

import jakarta.annotation.Resource;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;

@Component
public class queryDataHealthIndicator extends AbstractHealthIndicator {

	@Resource
	JdbcTemplate jdbcTemplate;
	@Override
	protected void doHealthCheck(Health.Builder builder) throws Exception {
		try {
			List<Map<String, Object>> res   = jdbcTemplate.queryForList("select * from user");
			if (res != null) {
				builder.status(Status.UP);
				builder.withDetail("status", "success");
				builder.withDetail("result", res);
			}
		} catch (DataAccessException e) {
			builder.withDetail("status","withException");
			builder.status(Status.DOWN);
		}
		builder.withDetail("code",200);
	}
}
